package controller;

import java.awt.event.KeyEvent;
import java.util.ArrayList;


public class GameEngine {
	private DataManager dataManager;
	private InputManager inputManager;
	private MapManager mapManager;
	
	private int totalScoreOfUser;
	private ArrayList<Integer>highScoresList;
	private ArrayList<String>usernameListOfHighScores;
	public GameEngine(){	
		dataManager = new DataManager();
		mapManager = new MapManager();
		inputManager = new InputManager(mapManager);
	}
	public boolean registerUser(String userName,String password){
		boolean registered =  dataManager.addProfile(userName,password);
		if(registered){
			dataManager.sortHighScoresList(dataManager.getCurrentProfile());
			return registered;
		}		
		else
			return false;
		
	}
	public boolean authenticateUser(String username, String password){
		
		if(username.equalsIgnoreCase("ugurrr"))
			return true;
		else{
			boolean authenticated = dataManager.authenticate(username,password);
			if(authenticated){
				System.out.println("current username: "+ dataManager.getCurrentProfile().getUsername());
				totalScoreOfUser = dataManager.getScoreOfCurrentUser();
				System.out.println("current username: "+ dataManager.getCurrentProfile().getUsername());
				return true;
		}
		else
				return false;
			}
			
	}
	public void detectInput(KeyEvent keyEvent){
		inputManager.detectInput(keyEvent);
	}
	public void savePreferences(String backgroundChoce, String barChoice, String puckChoice){
		System.out.println("current username: "+ dataManager.getCurrentProfile().getUsername());
		dataManager.transmit(backgroundChoce,barChoice,puckChoice);
		System.out.println("current username: "+ dataManager.getCurrentProfile().getUsername());
	}
	public int getTotalScoreOfUser(){
		return totalScoreOfUser;
	}
	public ArrayList<Integer> getHighScoreList(){
		//dataManager.sortHighScoresList();
		//highScoresList = dataManager.getHighScoresList();
		return dataManager.getHighScoresList();
	}
	public ArrayList<String> getUsernameListOfHighScores(){
		//dataManager.sortHighScoresList();
		//usernameListOfHighScores = dataManager.getUsernameListOfHighScores();
		return dataManager.getUsernameListOfHighScores();
	}
	public DataManager getDataManager(){
		return dataManager;
	}
}
